package com.lcc.lynx.jdbc.qw;

import lombok.Data;

@Data
public abstract class QwCondition {

    protected String columnName;
    protected TableDef tableDef;
    protected Object[] values;
    protected String tableAs;

    public abstract String build(QueryWrapper qw);

    public String tableColumnName(QueryWrapper qw) {
        if(tableAs == null && (tableDef == null || qw.getTableJoinList().size() == 1)){
            return columnName;
        }
        if(tableAs == null){
            tableAs = qw.getTableAsMap().get(tableDef.getTableName());
        }
        if(tableAs == null && qw.getParentAsMap() != null){
            tableAs = qw.getParentAsMap().get(tableDef.getTableName());
        }
        if(tableAs == null){
            tableAs = tableDef.getTableName();
        }
        return tableAs + "." + columnName;
    }
}
